//
//  TwoStateButton.m
//  ZingBrowser
//
//  Created by -Xh- on 1/22/13.
//  Copyright (c) 2013 -Xh-. All rights reserved.
//

#import "TwoStateButton.h"

@implementation TwoStateButton

@synthesize delegate;

-(void)initialize{
    isOnStateOne=YES;
    [self addTarget:self action:@selector(onTouchHere) forControlEvents:UIControlEventTouchUpInside];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self initialize];
    }
    return self;
}

-(void)swapState{
    if(isOnStateOne){
        isOnStateOne=NO;
        [self setImage:stateTwoImage forState:UIControlStateNormal];
        [self setImage:stateTwoHighLightImage forState:UIControlStateHighlighted];
    }else{
        isOnStateOne=YES;
        [self setImage:stateOneImage forState:UIControlStateNormal];
        [self setImage:stateOneHighLightImage forState:UIControlStateHighlighted];
    }
}

-(void)onTouchHere{
    if(isOnStateOne){
        if(delegate && [delegate respondsToSelector:@selector(onTouchStateOne:)]){
            [delegate onTouchStateOne:self];
        }
    }else{
        if(delegate && [delegate respondsToSelector:@selector(onTouchStateTwo:)]){
            [delegate onTouchStateTwo:self];
        }
    }
}

-(void)setImageOne:(UIImage *)_imageOne AndImageTwo:(UIImage *)_imageTwo{
    stateOneImage=_imageOne;
    stateTwoImage=_imageTwo;
    [self setImage:stateOneImage forState:UIControlStateNormal];

}

-(void)setHighLightImageOne:(UIImage *)_imageOne AndHighLightImageTwo:(UIImage *)_imageTwo{
    stateOneHighLightImage=_imageOne;
    stateTwoHighLightImage=_imageTwo;
    [self setImage:stateOneHighLightImage forState:UIControlStateHighlighted];
}
-(void)swapToState:(int)_state{
    if(_state==0){
        if(isOnStateOne){
            
        }else{//onStateTwo
            [self swapState];
        }
    }else{
        if(isOnStateOne){
            [self swapState];
        }else{
            
        }
    }
}

-(void)swapToStateInBool:(BOOL)_state{
    if(_state==NO){
        if(isOnStateOne){
            
        }else{//onStateTwo
            [self swapState];
        }
    }else{
        if(isOnStateOne){
            [self swapState];
        }else{
            
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
